package com.wlr.study.leetcode.week.compete;

/**
 * @author lerong.wang
 * @version 1.0.0
 * @description
 * @date 2025/4/30 16:53
 */
public class Leetcode3531 {

    public int countCoveredBuildings(int n, int[][] buildings) {
        int result = 0;
        for (int j = 0; j < buildings.length; j++) {
            int[] arr = new int[]{0, 0, 0, 0};
            int[] temp = buildings[j];
            int x = temp[0];
            int y = temp[1];
            for (int i = 1; i <= x; i++) {
                int[] left = new int[]{x - i, y};
                if (isAround(buildings, left)) {
                    arr[0] = 1;
                    break;
                }
            }
            if (arr[0]!=1) continue;
            for (int i = 1; i <= n - x; i++) {
                int[] right = new int[]{x + i, y};
                if (isAround(buildings, right)) {
                    arr[1] = 1;
                    break;
                }
            }
            if (arr[1]!=1) continue;
            for (int i = 1; i <= y; i++) {
                int[] top = new int[]{x, y - i};
                if (isAround(buildings, top)) {
                    arr[2] = 1;
                    break;
                }
            }
            if (arr[2]!=1) continue;
            for (int i = 1; i <= n-y; i++) {
                int[] bottom = new int[]{x, y + i};
                if (isAround(buildings, bottom)) {
                    arr[3] = 1;
                    break;
                }
            }
            if (arr[3]!=1) continue;
            result++;
            arr = new int[]{0, 0, 0, 0};
        }

        return result;
    }

    public boolean isAround(int[][] buildings, int[] around) {
        for (int[] row : buildings) {
            if (row.length != around.length) continue;
            boolean match = true;
            for (int i = 0; i < row.length; i++) {
                if (row[i] != around[i]) {
                    match = false;
                    break;
                }
            }
            if (match) return true;
        }
        return false;

    }

    public static void main(String[] args) {
        Leetcode3531 leetcode3531 = new Leetcode3531();
//        [1,2],[2,2],[3,2],[2,1],[2,3]
        System.out.println(leetcode3531.countCoveredBuildings(3, new int[][]{{1,2}, {2, 2}, {3, 2}, {2, 1},{2,3}}));
    }
}